
#!/usr/bin/python3
from IPy import IP
import subprocess

try:
    with open('ip.txt', 'a+') as fp:
        ip = IP('192.168.0.0/24')
        for i in ip:
            # 执行命令后，返回命令执行的结果和执行状态，0或非0
            res = subprocess.call(f'ping {i} -c 1 -i 0.1 -w 1', shell=True)
            if res == 0:
                fp.write(f'{i}ping通' + '\n')

            else:
                fp.write(f'{i}不能ping通' + '\n')

except FileNotFoundError:
    print('文件没有找到！')

